package edu.humc.dao;

import edu.humc.pojo.MessageTable;
import edu.humc.pojo.Recycle;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("MessageTableMapper")
public interface MessageTableMapper {
    @Insert("insert into messagetable values(#{mid},#{mdate},#{mtype},#{mtitle},#{mcontent},#{id})")
    int AddMessage(MessageTable messageTable);

    @Select("select * from messagetable where id=#{id}")
    @Results(@Result(column = "id",property = "username", one = @One(select="edu.humc.dao.UserMapper.SelectUsernameByid")))
    List<MessageTable> SelectMessage(int id);
//    删除留言
    @Delete("delete from messagetable where mid=#{mid}")
    int DeleteMessage(String mid);
//    展示留言详情
    @Select("select * from messagetable where mid=#{mid}")
    MessageTable DisplayDetail(String mid);
//    更新留言内容
    @Update("update messagetable set mtitle=#{mtitle},mcontent=#{mcontent} where mid=#{mid}")
    int UpdateMessage(MessageTable messageTable);
//    通过留言Id查找留言，和展示留言详情一致
//    添加回收站操作
    @Insert("insert into recycle values(#{mid},#{mdate},#{mtype},#{mtitle},#{mcontent},#{id},#{delete_date})")
//    int AddRecycle(MessageTable messageTable,@Param("delete_date") String delete_date);
    int AddRecycle(Recycle recycle);
}
